<?php
class userAuth extends fwDbObject
{
	public  $id = null;
	public  $login = null;
	public  $password = null;
	
	protected $_table_name = 'user_auth';
	protected $_table_prefix = 'ua';
	protected $_table_fields = array(
	'ua_i_id' => 'id'
	, 'ua_s_login' => 'login'
	, 'ua_s_password' => 'password'
	);
	
	public static function isLoginCorrect($login)
	{
		if(preg_replace('/[^a-zA-Z0-9_]/', '', $login) != $login)
			return false;
		if(strlen($login)<3)
			return false;
		if(strlen($login)>100)
			return false;
		return true;
	}
	
	public static function isLoginFree($login)
	{
		global $conf;
		$sql = 'SELECT	count(*)
				FROM	'.$conf['bdd']['prefix'].'user_auth
				WHERE	ua_s_login=\''.addslashes($login).'\'
						AND ua_d_deleted IS NULL';
		return (fwDB::getCell($sql)==0);
	}
}
?>